package com.maltys.backtracking;

import java.util.ArrayList;
import java.util.List;

/**
 * @author malty
 * @link <a href="https://leetcode.cn/problems/subsets/">子集</a>
 */
public class SubSets {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        backTracing(nums, 0, new ArrayList<>(), res);
        return res;
    }

    public void backTracing(int[] nums, int idx, List<Integer> list, List<List<Integer>> res) {
        if (idx > nums.length) {
            return;
        }
        res.add(new ArrayList<>(list));

        for (int i = idx; i < nums.length; i++) {
            list.add(nums[i]);
            backTracing(nums, i + 1, list, res);
            list.remove(list.size() - 1);
        }
    }

    public static void main(String[] args) {
        SubSets subSets = new SubSets();
        List<List<Integer>> subsets = subSets.subsets(new int[]{0});
        subsets.forEach(System.out::println);
    }
}
